#include <bits/stdc++.h>

using namespace std;

int main() {
	int n;
	cin >> n;
	vector <pair <int, int> > a(n);
	for (int i = 0; i < n; ++i) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end(), [](pair <int, int> a, pair <int, int> b) {
		return a.second > b.second;
	});
	long long s = 0;
	long long ans = 0;
	for (int i = 0; i < n; ++i) {
		s += a[i].first;
		ans = max(ans, s + a[i].second);
	}
	cout << ans;
	return 0;
}